<template>  
  <form @submit.prevent="addTodo">  
    <input type="text" v-model="newTodoText" placeholder="Add a new todo" required />  
    <button type="submit">Add</button>  
  </form>  
</template>  
  
<script>  
export default {  
  data() {  
    return {  
      newTodoText: ''  
    };  
  },  
  methods: {  
    addTodo() {  
      if (this.newTodoText.trim()) {  
        this.$emit('add', { text: this.newTodoText, id: Date.now() }); // 使用时间戳作为唯一ID  
        this.newTodoText = '';  
      }  
    }  
  }  
};  
</script>